/*
 * @Author: 0x9DEFA478
 * @Date: 2024-01-13 18:32:46
 * @LastEditTime: 2025-09-13 23:49:14
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * 
 */
#ifndef hConcurrency_H_Concurrency_std_HPP_
#define hConcurrency_H_Concurrency_std_HPP_
#include <mutex>
#include <chrono>
#include "./H_Concurrency_Empty.hpp"


#if __cplusplus >= 202000L
#include <semaphore>
#endif


namespace H{

  namespace Concurrency{

#if __cplusplus >= 202000L
    class Event_std{

      public:
        Event_std():E(0){}
        ~Event_std(){}

        bool TryAcquire(){return E.try_acquire();}

        void Acquire(){
          E.acquire();
        }

        bool Acquire(usize Timeout){
          if(Timeout==0){
            return E.try_acquire();
          }
          return E.try_acquire_for(std::chrono::milliseconds(Timeout));
        }

        bool Acquire_us(usize Timeout){
          if(Timeout==0){
            return E.try_acquire();
          }
          return E.try_acquire_for(std::chrono::microseconds(Timeout));
        }

        void Trigger(){
          E.release();
        }

      private:
        std::binary_semaphore E;
    };
#endif

    class Lock_std{

      public:
        Lock_std(){}
        ~Lock_std(){}

        void Lock(){
          L.lock();
        }
        
        void Unlock(){
          L.unlock();
        }

      private:
        std::recursive_mutex L;
    };

  }
}


#endif //hConcurrency_H_Concurrency_std_HPP_
